import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt

class Strech(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("设置伸缩量")
        self.resize(500,600)
        btn1=QPushButton(self)
        btn2=QPushButton(self)
        btn3=QPushButton(self)
        btn4=QPushButton(self)
        btn5=QPushButton(self)

        btn1.setText("按钮1")
        btn2.setText("按钮2")
        btn3.setText("按钮3")
        btn4.setText("按钮4")
        btn5.setText("按钮5")

        layout=QHBoxLayout()#水平布局
        layout.addStretch(0)#这样以来 所有的5个按钮都在右边了
        layout.addWidget(btn1)#
        layout.addWidget(btn2)
        layout.addWidget(btn3)
        layout.addWidget(btn4)
        layout.addWidget(btn5)

        self.setLayout(layout)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Strech()
    window.show()
    sys.exit(app.exec_())